<template>
  <header class="header">
    <!-- 第一行 -->
    <div class="top">
      <div class="container">
        <div class="loginList">
          <!-- 标题 -->
          <p>尚品汇奥利给</p>
          <!-- 登录部分 -->
<<<<<<< HEAD
          <p>
            <span>请</span>
            <router-link to="/Logon">登录</router-link>
            <router-link class="register" to="/Register">免费注册</router-link>
          </p>
          
=======
          <p v-if="!userName">
            <span>请</span>
            <router-link to="/Login">登录</router-link>
            <router-link class="register" to="/Register">免费注册</router-link>
          </p>
          <p v-else>
            <a>用户：{{userName}}</a>
            <a @click="logout" href="#javascript;" class="register">退出登录</a>
          </p>
     
>>>>>>> ecb56e7 (first commit)
          <!-- 右侧内容 -->
          <div class="typeList">
            <a href="#javascript;">我的订单</a>
            <a href="#javascript;">我的购物车</a>
            <a href="#javascript;">我的。。。</a>
            <a href="#javascript;">我的。。。</a>
            <a href="#javascript;">我的。。。</a>
            <a href="#javascript;">我的。。。</a>
            <a href="#javascript;">我的。。。</a>
            <a href="#javascript;">我的。。。</a>
          </div>
        </div>
      </div>
    </div>

    <!-- 第二行 logo与搜索 -->
    <div class="bottom">
      <!-- logo -->
      <h1 class="logoArea">
        <!-- 声明式导航 -->
        <router-link class="logo" to="/Home">
          <img src="../../assets/logo1.png" alt="logo">
        </router-link>
      </h1>
      <!-- 搜索 -->
      <div class="searchArea">
        <form action="###" class="searchForm">
          <input type="text" id="autocomplete" v-model:value="value" class="input-error input-xxlarge">
          <!-- 编程式路由导航 -->
<<<<<<< HEAD
          <button class="sui-btn btn-xlarge btn-danger" type="button" @click="search">搜索</button>
=======
          <button class="sui-btn btn-xlarge btn-danger" type="button" @click="search">搜索</button>        
>>>>>>> ecb56e7 (first commit)
        </form>
      </div>
    </div>
  </header>
</template>

<script>
export default {
  name: "Header",
  data() {
    return {
      value: "",
    }
  },
<<<<<<< HEAD
  methods: {
    search() {
      // this.$router.push(`/Search/${this.value}`);
      this.$router.push({
        // path: "/Search",
        name: "search",
        query: {
          data: this.value,
        },
        params: {
          keys: this.value || undefined,
        },        
      });
    }
  },
=======
  methods: {    
    search() {      
      let location = {
        name: "search",
        params: {
          keyword: this.value || undefined,
        }, 
      };
      
      if(this.$route.query) { location.query = this.$route.query; };           

      // 跳转
      this.$router.push(location);
      
      this.value = "";
    },
    
    async logout() {
      try {
        await this.$store.dispatch("userLogout");
        await this.$router.push("/Home");
      }
      catch(err) {
        console.log("退出失败");
      }
      
    }
  },
 
  computed: {
    userName() {      
      return this.$store.state.register.userInfo?this.$store.state.register.userInfo.data.name:false;
    }
  }
>>>>>>> ecb56e7 (first commit)
}
</script>

<style scoped>
  /* 基本样式 */
  .header .top {
    background-color: #eaeaea;
    height: 30px;
    line-height: 30px;
  }
  .header .top .container {
    width: 1200px;
    margin: 0 auto;
    overflow: hidden;
  }
   /* 左侧 登录 */
  .header .top .loginList p {    
    float: left;
    margin-right: 10px;
  }
  .header .top .loginList p .register {
    border-left: 1px solid #b3aeae;
    padding: 0 5px;
    margin-left: 5px;
  }
  /* 右侧 列表 */
  .header .top .loginList .typeList {
    float: right;
  }
  .header .top .loginList .typeList a {
    padding: 0 10px;
    border-left: 1px solid #b3aeae;
  }
  .header .top .loginList .typeList a:nth-child(1) {
    border: 0px;
  }


  /* 基本样式 */
  .header .bottom {
    width: 1200px;
    margin: 0 auto;
    overflow: hidden;
  }
  /* logo */
  .header .bottom .logoArea {
    float: left;
  }
  .header .bottom .logoArea .logo img {
    width: 175px;
    margin: 25px 45px;
  }
  /* 搜索 */
  .header .bottom .searchArea {
    float: right;
    margin-top: 35px;
  }
  .header .bottom .searchArea .searchForm {
    overflow: hidden;
  }
  .header .bottom .searchArea .searchForm input {
    box-sizing: border-box;
    width: 490px;
    height: 32px;
    padding: 0px 4px;
    border: 2px solid #ea4a36;
    float: left;
  }
  .header .bottom .searchArea .searchForm input:focus {
    outline: none;
  }
  .header .bottom .searchArea .searchForm button {
    height: 32px;
    width: 68px;
    background-color: #ea4a36;
    border: none;
    color: #fff;
    float: left;
    cursor: pointer;
  }
  .header .bottom .searchArea .searchForm button:focus {
    outline: none;
  }
</style>